package com.gao.sentinel.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    @Autowired
    private RedisPropertiesConfig redisProperties;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        String redisUrl = String.format("redis://%s:%s", redisProperties.getRedisMaster().getRedisNode().getHost()+ "", redisProperties.getRedisMaster().getRedisNode().getPort() + "");
        config.useSingleServer().setAddress(redisUrl)
                                //.setPassword(redisProperties.getPassword())
                                .setDatabase(redisProperties.getRedisMaster().getRedisNode().getDatabase());
        return Redisson.create(config);
    }
}
